<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 比如我要过滤 "SM"
        var arr = ['SM', '垃圾']

        var str = 'asdasdSMasdasdasdSMsdasdasdSMsadasd垃圾sssd垃圾'

        // var res = str.replaceAll(arr[0], '**');
        // console.log(res);
        // res = res.replaceAll(arr[1], '**');
        // console.log(str);
        // console.log(res);

        arr.forEach(function (v) {
            v//每一个敏感词
            //  都把替换以后的结果 赋值给 str自己
            str = str.replaceAll(v, '**');
            console.log(str);
        });

        // 需要结果
        // asdasd**asdasdasd**sdasdasd**


    </script>

</body>

</html>